package it.learn.kafka.test;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public class UserConcatMapExample {

    public static void main(String[] args) {
        // Flux.just(1L, 2L, 3L)
        //     .concatMap(userId -> getUserDetails(userId))
        //     .subscribe(System.out::println); // 输出用户详细信息
        Mono<Long> map = Flux.just(1L, 2L, 3L)
                .concatMap(userId -> Mono.just(userId).filterWhen(id -> Mono.just(id > 1)))
                .next()
                .map(uid -> uid + 10L);
        map.subscribe(System.out::println);
    }

    private static Mono<User> getUserDetails(Long userId) {
        // 模拟异步操作，获取用户详细信息
        return Mono.fromCallable(() -> new User(userId, "User" + userId));
    }

    static class User {
        private Long id;
        private String name;

        public User(Long id, String name) {
            this.id = id;
            this.name = name;
        }

        @Override
        public String toString() {
            return "User{id=" + id + ", name='" + name + "'}";
        }
    }
}